import { lazy } from "react";
import type { RouteObject } from "react-router-dom";
import { Navigate } from "react-router-dom";

// 页面组件懒加载
const Layout = lazy(() => import("@/components/layout"));
const Cas = lazy(() => import("@/pages/cas"));
const Login = lazy(() => import("@/pages/login"));
const Register = lazy(() => import("@/pages/register"));
const Forgot = lazy(() => import("@/pages/forgot"));
const Profile = lazy(() => import("@/pages/profile"));
const CasError = lazy(() => import("@/pages/cas-error"));
const NotFound = lazy(() => import("@/pages/not-found"));

export const routes: RouteObject[] = [
  {
    path: "/",
    element: <Layout />,
    handle: {
      title: "CAS Authentication Center",
      description: "Welcome to the unified authentication system.",
      index: "/", // unique key for the route
    },
    children: [
      {
        index: true,
        element: <Navigate to="/cas" replace />,
      },
      {
        path: "cas",
        element: <Cas />,
        handle: {
          index: "/cas",
          title: "CAS Authentication Center",
          description: "Welcome to the unified authentication system.",
        },
      },
      {
        path: "cas/login",
        element: <Login />,
        handle: {
          index: "/cas/login",
          title: "Sign In",
          description: "Please enter your email and password.",
        },
      },
      {
        path: "cas/register",
        element: <Register />,
        handle: {
          index: "/cas/register",
          title: "Sign up",
          description: "Create your new account.",
        },
      },
      {
        path: "cas/forgot",
        element: <Forgot />,
        handle: {
          index: "/cas/forgot",
          title: "Forgot Password",
          description: "Please enter the email used for update password.",
        },
      },
      {
        path: "cas/profile",
        element: <Profile />,
        handle: {
          index: "/cas/profile",
          title: "User Profile",
          description: "View and manage your profile information.",
        },
      },
      {
        path: "cas/error",
        element: <CasError />,
        handle: {
          index: "/cas/error",
          title: "Error",
          description: "An error occurred during the authentication process.",
        },
      },
      {
        path: "*",
        element: <NotFound />,
        handle: {
          index: "/not-found",
          title: "Page Not Found",
          description: "The page you are looking for does not exist",
        },
      },
    ],
  },
];
